/*
 * @Descripttion: 
 * @version: 请写项目版本
 * @Author: @cdm
 * @Date: 2021-09-08 13:54:32
 * @LastEditors: @cdm
 * @LastEditTime: 2021-12-20 14:11:39
 * No pains no gains
 */


import { game } from "../../../../script/game/control/game";
import { cardType, edu } from "../../../../script/game/gameType";
import { ListItem } from "../../../../script/util/ListView/ListItem";
import { ccs } from "../../../../script/util/services";
import { TouchExtend } from "../../../../script/util/TouchExd";
import { touchExd } from "../../../../script/util/TouchExtend";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends ListItem<cardType> {
  
    @property(cc.Button)
    ensure: cc.Button = null;
    
    @property(cc.Label)
    title: cc.Label = null;

    @property(cc.Label)
    desc: cc.Label = null;

    @property(cc.Label)
    need: cc.Label = null;

    @property(cc.Label)
    price: cc.Label = null;

    @property(cc.Label)
    leftTime: cc.Label = null;

    @property(cc.Node)
    icon: cc.Node = null;

    @property(cc.Node)
    pass: cc.Node = null;

    @property(cc.Node)
    mask: cc.Node = null;

    start () {

    }
    initItem(data: cardType, index: number) {

        this.title.string = data.name;
        ccs.spriteExd.setSprite(this.icon, ccs.resMgr.getCompanyIcon(data.id));
        this.desc.string = data.desc|| "证书是个好东西";
        let temp = "";
        temp += ccs.dataMgr.getEduById(data.need.edu).name;
        this.need.string = temp;
        this.price.string = "¥" + (data.cost || 3000);
        if(data.leftTime > 0) {
            this.leftTime.string = "下次考试时间：" + data.leftTime + "个月后";
            this.leftTime.node.active = true;
        } else {
            this.leftTime.node.active = false;
        }
        if(game.playerMgr.bag.cardBag.getItem(data.id)) {
            this.ensure.node.active = false;
            this.pass.active = true;
            this.mask.active = false;
            this.leftTime.node.active = false;
            return ;
        } else {
            if(edu[data.need.edu] > edu[game.playerMgr.heroInfo.edu.id]) {
                this.mask.active = true;
            } else {
                this.mask.active = false;
            }
        }
        TouchExtend.touchEndScale(this.ensure.node, () => { this.toTest(data) });
    }
    onItemclick(data: cardType) {
    }
    toTest(data: cardType) {
        if(data.leftTime > 0) {
            ccs.winMgr.showWin("toast", { msg: "还未到报考时间"});
            return;
        }
        if(edu[data.need.edu] > edu[game.playerMgr.heroInfo.edu.id]) {
            ccs.winMgr.showWin("toast", { msg: "学历不够无法报考"});
            return;
        }
        if(!game.playerMgr.calMoney(-data.cost)) {
            return ;
        }
        ccs.winMgr.showWin("popTestWin", { id: data.id })
    }
    // update (dt) {}
}
